let app = getApp();
Page({
  data: {
    // 下拉框显示判断 open
    open: false,
    order_data: {},
    car_list: [],
    // 弹框
    hiddenmodalput: true
  },
  //获取地图传回的数据
  onLoad: function(option) {
    let that = this;
    if (option.index == '1') {
      app.globalData.order_data.go_place = option.destination
    }
    if (option.index == '2') {
      app.globalData.order_data.get_girl_place = option.destination
    }
    if (option.index == '3') {
      app.globalData.order_data.return_place = option.destination
    }
    if (option.index == '4') {
      app.globalData.order_data.hotel_place = option.destination
    }
    this.setData({
      order_data: app.globalData.order_data,
      car_list: app.globalData.car_list,
    });
  },
  // 保存名字
  nameInput: function(e) {
    app.globalData.order_data.name = e.detail.value
  },
  // 保存电话
  phoneInput: function(e) {
    app.globalData.order_data.phone = e.detail.value
  },
  // 租车日期 
  datePickerBindchange: function(e) {
    app.globalData.order_data.rent_date = e.detail.value;
    this.onShow()
  },
  // 车队明细 select
  // car_change: function(e) {
  //   this.setData({
  //     car_index: e.detail.value
  //   })
  // },

  //跳转到地图
  // 出发地点
  do_map1: function(e) {
    let that = this;
    var index = '1'
    wx.navigateTo({
      url: '/pages/map/map?index=' + index
    })
  },
  // 娶亲地点
  do_map2: function() {
    var index = '2'
    wx.navigateTo({
      url: '/pages/map/map?index=' + index
    })
  },
  //返回地点
  do_map3: function() {
    var index = '3'
    wx.navigateTo({
      url: '/pages/map/map?index=' + index
    })
  },
  // 酒店地点
  do_map4: function() {
    var index = '4'
    wx.navigateTo({
      url: '/pages/map/map?index=' + index
    })
  },
  // 车队明细下拉框
  showitem: function() {
    this.setData({
      open: !this.data.open
    })
  },


  timePickerBindchange: function(e) {
    this.setData({
      arrive_time: e.detail.value
    })
  },

  //点击按钮痰喘指定的hiddenmodalput弹出框
  modalinput: function() {
    this.setData({
      hiddenmodalput: !this.data.hiddenmodalput
    })
  },
  //取消按钮
  cancel: function() {
    this.setData({
      hiddenmodalput: true
    });
  },
  //确认
  confirm: function() {
    this.setData({
      hiddenmodalput: true
    })
  },

  // 提交
  formSubmit: function(e) {
    let {
      phone,
      name,
      go_place,
      get_girl_place,
      return_place
    } = e.detail.value;
    var data = e.detail.value;

    if (phone == '' || name == '' || go_place == '' || get_girl_place == '' || return_place == '') {
      this.setData({
        warn: "*必须填写哦！",
        isSubmit: true
      })
      wx.showToast({
        title: '*必须填写哦！',
        icon: 'loading',
        duration: 2000
      })
    }

    // 判断手机号码
    if (phone.length != 11) {
      this.setData({
        warn: "号码不规范哦~",
        isSubmit: true
      })
      wx.showToast({
        title: '号码长度不对哦~',
        icon: 'loading',
        duration: 2000
      })
      return;
    }

    var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
    if (!myreg.test(phone)) {
      this.setData({
        warn: "号码不规范哦~",
        isSubmit: true
      })
      wx.showToast({
        title: '号码不规范哦~',
        icon: 'loading',
        duration: 2000
      })
      return;
    }

    // if (phone != myreg) {
    //   this.setData({
    //     warn: "请输入正确的手机号！",
    //     isSubmit: true
    //   })
    //   return;
    // }
    wx.redirectTo({
      url: '/pages/comming/comming',
    })
    wx.request({
      url: app.globalData.hostname + ":" + app.globalData.port + '/create/mk_crm',
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      },
      data: {
        crm_data: e.detail.value,
        car_list: app.globalData.car_list,
        user_id: app.globalData.wxid
      },
      success: function(res) {
        app.globalData.order_data.go_place = ''
        app.globalData.order_data.get_girl_place = ''
        app.globalData.order_data.return_place = ''
        app.globalData.order_data.hotel_place = ''
        app.globalData.car_list = []
      }
    })
    // 跳转到报价单

  },
  formReset: function() {
  },
  onShow: function() {
    this.setData({
      order_data: app.globalData.order_data,
      car_list: app.globalData.car_list,
    });
  }
})